# -*- coding: utf-8 -*-
# @Time    : 2024/9/11 下午9:06
# @Author  : liujun
# @Email   : 2592730854@qq.com
# @File    : run.py.py
# @Software: PyCharm

"""
执行模块
"""

import pytest
from common import log
from common import shell
from config import config
from common import mail
from common import consts
from common.tools import zip_dir

if __name__ == '__main__':
    conf=config.Config()
    log =log.Log.get_logger()
    log.info('初始化配置文件,path='+ conf.log_path)

    shell = shell.Shell()
    xml_report_path=consts.XML_REPORT_PATH
    html_report_path=consts.HTML_REPORT_PATH
    cases_path=consts.CASE_PATH
    attach_file='report.zip'

    # 定义测试集
    args = ['-s','-q','--alluredir',xml_report_path,'--clean-alluredir',cases_path]
    pytest.main(args)

    cmd = 'allure generate {} -o {} --clean'.format(xml_report_path,html_report_path)


    try:
        shell.execute(cmd)
    except Exception:
        log.error('执行用例失败,请检查环境配置’')

    # 压缩 report 文件夹
    zip_dir(consts.REPORT_PATH, attach_file)

    try:
        mail = mail.send_email(attach_file)
    except Exception as e:
        log.error('发送邮件失败，请检查邮件配置')
        raise


